package io.geekidea.boot.test.controller;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.test.dto.PayRecordDto;
import io.geekidea.boot.test.query.PayRecordQuery;
import io.geekidea.boot.test.service.PayRecordService;
import io.geekidea.boot.test.vo.PayRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 消费记录 控制器
 *
 * @author geekidea
 * @since 2025-03-26
 */
@Slf4j
@RestController
@Tag(name = "消费记录")
@RequestMapping("/admin/payRecord")
public class PayRecordController {

    @Autowired
    private PayRecordService payRecordService;

    /**
     * 添加消费记录
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加消费记录")
    @PostMapping("/addPayRecord")
    @Permission("pay:record:add")
    public ApiResult addPayRecord(@Valid @RequestBody PayRecordDto dto) {
        log.info("添加消费记录：{}", dto);
        boolean flag = payRecordService.addPayRecord(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改消费记录
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改消费记录")
    @PostMapping("/updatePayRecord")
    @Permission("pay:record:update")
    public ApiResult updatePayRecord(@Valid @RequestBody PayRecordDto dto) {
        log.info("修改消费记录：{}", dto);
        boolean flag = payRecordService.updatePayRecord(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除消费记录
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除消费记录")
    @PostMapping("/deletePayRecord/{id}")
    @Permission("pay:record:delete")
    public ApiResult deletePayRecord(@PathVariable Long id) {
        log.info("删除消费记录：{}", id);
        boolean flag = payRecordService.deletePayRecord(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取消费记录详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取消费记录详情")
    @PostMapping("/getPayRecord/{id}")
    @Permission("pay:record:info")
    public ApiResult<PayRecordVo> getPayRecord(@PathVariable Long id) {
        log.info("获取消费记录详情：{}", id);
        PayRecordVo payRecordVo = payRecordService.getPayRecordById(id);
        return ApiResult.success(payRecordVo);
    }

    /**
     * 获取消费记录分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取消费记录分页列表")
    @PostMapping("/getPayRecordPage")
    @Permission("pay:record:page")
    public ApiResult<PayRecordVo> getPayRecordPage(@Valid @RequestBody PayRecordQuery query) {
        log.info("获取消费记录分页列表：{}", query);
        Paging<PayRecordVo> paging = payRecordService.getPayRecordPage(query);
        return ApiResult.success(paging);
    }

}
